package pl.matt.dao.impl;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import pl.matt.dao.AbstractNamedEntityDao;
import pl.matt.model.AbstractNamedEntity;

public class HibernateAbstractNamedEntityDao<T extends AbstractNamedEntity> extends HibernateAbstractEntityDao<T> implements AbstractNamedEntityDao<T> {

	protected HibernateAbstractNamedEntityDao(Class<T> entityClass) {
		super(entityClass);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<T> readAllByName(String name) {
		Criteria criteria = createCriteria().add(Restrictions.eq("name", name));
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public T readByName(String name) {
		Criteria criteria = createCriteria().add(Restrictions.eq("name", name));
		return (T) criteria.uniqueResult();
	}



}
